package org.yoki.edu.portal.task.radius;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;
import org.yoki.edu.portal.core.radius.domain.Radcheck;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Sky$
 * @Description: TODO
 * @date 2017/11/1$ 11:34$
 */
@RestController
@EnableScheduling
public class RadiusClearUpTask {

    private static Logger logger = LoggerFactory.getLogger(RadiusClearUpTask.class);

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;

    /**
     * 定时清理用户表radcheck
     */
    //每天1点执行
    @Scheduled(cron = "0 0 1 * * ?")
//    @Scheduled(cron = "*/20 * * * * ?")
    public void featureStatistics() {
        logger.info("Clear up table named radchek By Cron: The time is now " + sdf.format(new Date()));
        Calendar calendar = Calendar.getInstance();   //此时打印它获取的是系统当前时间
        calendar.add(Calendar.DATE, -2);    //得到前两天
        Date preDate = calendar.getTime() ;
        Radcheck.deleteWeChatTempUser(preDate);
//        Radcheck.deletePhoneTempUser(preDate);
    }

}
